package com.beone.admin.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.beone.admin.exception.MvcException;
import com.beone.admin.annotation.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.beone.admin.common.AdminConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import com.beone.admin.entity.TaskTemplateDetail;
import com.beone.admin.service.TaskTemplateDetailService;
import java.io.Serializable;

import org.springframework.stereotype.Controller;
import com.base.SuperController;


/**
 * @Title 排班模板明细 前端控制器
 * @Author 秦波
 * @Version 1.0 on 2019-06-01
 * @Copyright 贝旺科权
 */
@Controller
@RequestMapping("/admin/taskTemplateDetail")
@Api(value = "排班模板明细管理模块", tags = {"排班模板明细管理接口"})
public class TaskTemplateDetailController extends SuperController {

private static final Logger log = LoggerFactory.getLogger(TaskTemplateDetailController.class);

@Autowired
private TaskTemplateDetailService taskTemplateDetailService;

    /**
     * 排班模板明细管理 入口 --> index
     * @return
     */
    @GetMapping("")
    public String index() throws MvcException{
        return "taskTemplateDetail/index";
    }

    /**
     * 排班模板明细管理 显示添加页面
     * @return
     */
    @GetMapping("/showAdd")
    public String showAdd()  throws MvcException{
        return "taskTemplateDetail/form";
    }


    /**
     * 排班模板明细管理 显示修改页面
     * @return
     */
    @GetMapping("/showUpdate/{id}")
    public String showUpdate(@PathVariable("id") String id, ModelMap model) throws MvcException{
        try {
            model.addAttribute("id", id);
            model.addAttribute("entity", taskTemplateDetailService.selectById(id));
        }catch (Exception e) {
            log.error("showUpdate 异常 e = {}", e);
            throw new MvcException(e.getMessage());
        }
        return "taskTemplateDetail/form";
    }

    /**
     * 排班模板明细管理分页列表 JSON
     * @param entity
     * @param currPage
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "排班模板明细列表", notes = "排班模板明细列表分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true
                    , paramType = "param", dataType = "int"),
            @ApiImplicitParam(name = "rows", value = "每页最大显示记录数", required = true
                    , paramType = "param", dataType = "int")
    })
    @RequestMapping(value = "/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE
            , method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public Object showList(TaskTemplateDetail entity,
    @RequestParam(value = "page", defaultValue = AdminConstants.DEFAULT_PAGE_NUM) int currPage,
    @RequestParam(value = "rows", defaultValue = AdminConstants.PAGE_SIZE) int pageSize) {
            return  taskTemplateDetailService.getTaskTemplateDetailPagination(entity, currPage, pageSize);
    }

    /**
     *  保存排班模板明细
     * @param entity
     * @return
     */
    @ApiOperation(value = "保存排班模板明细", notes = "保存排班模板明细 主键属性为空新增,否则修改")
    @ApiImplicitParam(name = "entity", value = "{title}详细实体", required = true
            , paramType = "form", dataType = "object")
    @Log(desc = "排班模板明细", type = Log.LOG_TYPE.SAVE)
    @PostMapping(value = "/save", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public Object save(TaskTemplateDetail entity) {
        if(taskTemplateDetailService.insertOrUpdate(entity)){
            return super.responseResult("success", "成功！");
        }
        return super.responseResult("fail", "失败！");
    }

;
    /**
     * 删除排班模板明细
     * @param id
     * @return
     */
    @ApiOperation(value = "删除排班模板明细", notes = "根据排班模板明细Id，删除排班模板明细")
    @ApiImplicitParam(name = "id", value = "实体ID", required = true, paramType = "param", dataType = "object")
    @Log(desc = "删除排班模板明细", type = Log.LOG_TYPE.DEL)
    @PostMapping(value = "/delete/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public Object delete(@PathVariable("id") Integer id) {
        if(taskTemplateDetailService.deleteById(id)){
            return super.responseResult("success", "成功！");
        }
        return super.responseResult("fail", "失败！");
    }
}
